package com.siwei.mes.controller.materials;

import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.entity.materials.MaterialsTestProjectDesc;
import com.siwei.mes.service.materials.MaterialsTestProjectDescService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 试验说明表相关
 *
 * @author linzi
 * @since 2024-05-18 23:25:58
 */
@Api(value = "试验说明表")
@RestController
@RequestMapping("materialsTestProjectDesc")
public class MaterialsTestProjectDescController {
    @Resource
    private MaterialsTestProjectDescService materialsTestProjectDescService;

    @ApiOperation(value = "新增试验说明表")
    @PostMapping("/create")
    public Json create(@RequestBody @Validated(AddGroup.class) MaterialsTestProjectDesc entity) {
        return Json.succ().data(ApiResult.addColumn("id", materialsTestProjectDescService.create(entity)));
    }

    @ApiOperation(value = "修改试验说明表")
    @PostMapping("/update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) MaterialsTestProjectDesc entity) {
        materialsTestProjectDescService.update(entity);
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "删除试验说明表")
    @PostMapping("/delete")
    public Json delete(@RequestBody MaterialsTestProjectDesc entity) {
        materialsTestProjectDescService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "分页获取试验说明表")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<MaterialsTestProjectDesc, MaterialsTestProjectDesc> query) {
        return Json.succ().data(materialsTestProjectDescService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取试验说明表")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(materialsTestProjectDescService.loadById(id));
    }

    @ApiOperation(value = "根据itemCode获取试验说明表")
    @GetMapping("loadByItemCode")
    public Json loadByItemCode(@RequestParam("itemCode") String itemCode) {
        return Json.succ().data(materialsTestProjectDescService.loadByItemCode(itemCode));
    }


    @ApiOperation(value = "获取所有试验说明表")
    @PostMapping("getAll")
    public Json getAll(@RequestBody MaterialsTestProjectDesc entity) {
        return Json.succ().data(ApiResult.addList(materialsTestProjectDescService.getAll(entity)));
    }

}
